package com.avengers.modules.spider.whois.querier;

import com.avengers.core.bean.enums.SymbolEnum;
import com.avengers.core.kit.DomainKit;
import com.avengers.modules.spider.whois.bean.WhoisInfo;

interface WhoisAnalysis {

    String server();

    String notFoundRemark();

    String unRegisteredOnLineRemark();

    /**
     * String转换成bean
     *
     * @param domain   域名
     * @param whoisMsg whois info
     */
    default WhoisInfo transfer(String domain, String whoisMsg) {
        if (null == domain || domain.isEmpty()) {
            return null;
        }
        if (!DomainKit.isDomain(domain)) {
            return null;
        }
        if (null == whoisMsg || whoisMsg.isEmpty()) {
            return null;
        }
        String[] lines = whoisMsg.split(SymbolEnum.carriageReturn.string);
        WhoisInfo whoisInfo = new WhoisInfo(domain);
        for (String s : lines) {
            String line = s.trim();
            if (line.isEmpty()) {
                continue;
            }
            transferLine(whoisInfo, line);
        }
        return whoisInfo;
    }

    /**
     * 行转换
     *
     * @param whoisInfo whois对象
     * @param line      行字符串
     */
    void transferLine(WhoisInfo whoisInfo, String line);
}
